﻿#ifndef OPEN62541_H
#define OPEN62541_H

#include <QVariant>
#include <open62541/client_config_default.h>
#include <open62541/client_highlevel.h>

#include <QDebug>

class Open62541
{
public:
    Open62541();

    /**
     * @brief OpcUA_Init
     * @param endpointUrl   opc.tcp://127.0.0.1:49320
     * @return
     */

    bool Open62541_Init(QString endpointUrl);

    bool Open62541_WriteData(int nsIndex, QString tagPath, bool data);     //bool

    bool Open62541_WriteData(int nsIndex, QString tagPath, int16_t data);  //short

    bool Open62541_WriteData(int nsIndex, QString tagPath, uint8_t data);  //byte

    bool Open62541_ReadData(int nsIndex, QString tagPath, bool& data);  //bool

    bool Open62541_ReadData(int nsIndex, QString tagPath, int16_t& data);  //short

    bool Open62541_ReadData(int nsIndex, QString tagPath, uint8_t& data);  //byte

    //只为读取实时压力值用
    bool Open62541_ReadData(int nsIndex, QString tagPath, int32_t& data);  //Dint

    bool Open62541_batchReading(int nsIndex, QStringList tagPaths, QMap<QString, QVariant>& data);

protected:
    QVariant variantFromUaValue(const UA_Variant &uaVariant);

    bool convertToUaVariant(const QVariant &qVar, UA_Variant &uaVar);

    UA_Client * client;

};

#endif // OPEN62541_H
